package com.hacpai.android.md.ui.adapter;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckedTextView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hacpai.android.md.R;
import com.hacpai.android.md.model.entity.Domain;
import com.hacpai.android.md.model.storage.LoginShared;
import com.hacpai.android.md.presenter.contract.IReplyPresenter;
import com.hacpai.android.md.presenter.implement.ReplyPresenter;
import com.hacpai.android.md.ui.activity.LoginActivity;
import com.hacpai.android.md.ui.activity.UserDetailActivity;
import com.hacpai.android.md.ui.util.ToastUtils;
import com.hacpai.android.md.ui.view.ICreateReplyView;
import com.hacpai.android.md.ui.view.IReplyView;
import com.hacpai.android.md.ui.widget.ContentWebView;
import com.hacpai.android.md.util.FormatUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class DomainListAdapter extends BaseAdapter {

    private final Activity activity;
    private final LayoutInflater inflater;
    private final List<Domain> domainList = new ArrayList<>();



    public DomainListAdapter(@NonNull Activity activity) {
        this.activity = activity;
        inflater = LayoutInflater.from(activity);

    }

    public List<Domain> getDomainList() {
        return domainList;
    }

    public void setDomainList(@NonNull List<Domain> domainList) {
        this.domainList.clear();
        Domain domain = new Domain();
        domain.setDomainDescription("全部的领域");
        domain.setDomainIconPath("null");
        domain.setDomainTagCnt(0);
        domain.setDomainTitle("全部");
        domain.setDomainURI("null");
        domain.setoId("all");
        domainList.add(domain);

        this.domainList.addAll(domainList);
    }

    @Override
    public int getCount() {
        return domainList.size();
    }

    @Override
    public Object getItem(int position) {
        return domainList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_domain, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.update(position);
        return convertView;
    }

    protected class ViewHolder {

        @BindView(R.id.btn_domain_nav)
        protected CheckedTextView btn_domain_nav;

        private Domain domain;
        protected ViewHolder(@NonNull View itemView) {
            ButterKnife.bind(this, itemView);
        }

        protected void update(int position) {
            domain = domainList.get(position);
            btn_domain_nav.setText(domain.getDomainTitle());
            btn_domain_nav.setCompoundDrawablesRelative(activity.getResources().getDrawable(R.drawable.main_nav_ic_all),null,null,null);
            btn_domain_nav.setCompoundDrawables(activity.getResources().getDrawable(R.drawable.main_nav_ic_all),null,null,null);
        }

    }




}
